#!/bin/bash
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/latest/bin:/usr/java/latest/jre:/root/bin

Vip1='192.168.30.21'
Vip2='192.168.30.22'
Vip3='192.168.30.23'
Vip4='192.168.30.24'

zabbix_Agent=${HOSTNAME}

zababix_Server='192.168.30.17'

Sender_Key1='B2_Vip_master_192.168.30.21'
Sender_Key2='B2_Vip_master_192.168.30.22'
Sender_Key3='B2_Vip_master_192.168.30.23'
Sender_Key4='B2_Vip_master_192.168.30.24'

#获取vip是否在master节点 
Site_mysql_vip_status=$(ip addr | grep -c "${Vip1}")
DW_mysql_vip_status=$(ip addr | grep -c "${Vip2}")
Site_tomcat_vip_status=$(ip addr | grep -c "${Vip3}")
Site_node_vip_status=$(ip addr | grep -c "${Vip4}")


#发送到zabbix服务器端,master端若为1则正常,若为0则不正常,backup服务器则相反
zabbix_sender -s "${zabbix_Agent}" -z "${zababix_Server}" -k "${Sender_Key1}" -o "${Site_mysql_vip_status}"
zabbix_sender -s "${zabbix_Agent}" -z "${zababix_Server}" -k "${Sender_Key2}" -o "${DW_mysql_vip_status}"
zabbix_sender -s "${zabbix_Agent}" -z "${zababix_Server}" -k "${Sender_Key3}" -o "${Site_tomcat_vip_status}"
zabbix_sender -s "${zabbix_Agent}" -z "${zababix_Server}" -k "${Sender_Key4}" -o "${Site_node_vip_status}"
